<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="/shop/include :: loginHeader"></head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>layuiAdmin</h2>
            <p>layui 官方出品的单页面后台管理模板系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="userName" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="passWord" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" class="layui-input">
            </div>
            <div id="mpanel1">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>
        </div>
    </div>
</div>
<div th:include="/shop/include::loginFooter"></div>
<script>
    var code = false;
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router()
            , search = router.search;

        var login = {
            //初始化页面跳转，为了防止从iframe跳转到login页面直接在iframe中显示login页面
            initPage: function () {
                //alert(location.href);
                if (window.top != window.self) {
                    top.location.href = location.href;
                }
            },
        }

        $(function () {
            login.initPage();
        });


        form.render();


        $('#mpanel1').slideVerify({
            type: 1,		//类型
            vOffset: 0,	//误差量，根据需求自行调整
            barSize: {
                width: '80%',
                height: '40px',
            },
            ready: function () {
            },
            success: function () {
                code = true;
            },
            error: function () {
            }

        });

        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            if (!code) {
                layer.msg("请进行滑动验证")
                return false;
            }
            //请求登入接口
            admin.req({
                url: "/platform/platformaccount/platformLogin" //实际使用请改成服务端真实接口
                , data: obj.field
                , type: "post"
                , done: function (res) {
                    //请求成功后，写入 access_token
                    if (res.status == "SUCCESS") {
                        window.sessionStorage.setItem("tokenName","platform_token")
                        window.sessionStorage.setItem("platform_token",res.data.token)
                        window.sessionStorage.setItem("platform_ID",res.data.data.id)
                        window.sessionStorage.setItem("platform_nickName",res.data.data.nickName)
                        //登入成功的提示与跳转
                        layer.msg('登入成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            location.href = '/platform/page/'; //后台主页
                        });
                    } else {
                        layer.msg(res.message);
                        return false;
                    }
                }
            });
        });
    });
</script>
<script language="javascript">        //防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
});
</script>
</body>
</html>